// app.js
App({
  onLaunch(options) {

    wx.hideHomeButton(); 
    
    // 展示本地存储能力
    const { scene } = options
    if (scene) {
      this.globalData.userEnterAppletMode = scene
    }

    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    let res = wx.getSystemInfoSync();
    let statusHeight = res.statusBarHeight; // 注意：此时获取到的值的单位为 'px'

    this.globalData.statusBarHeight = statusHeight
  },
  onShow(){
   // wx.hideHomeButton(); 
    this.onNetworkStatusChange()  //开启检测
  },
  onNetworkStatusChange() {
    var that = this
    //获取网络类型
    wx.getNetworkType({
      success: function (res) {
        const networkType = res.networkType
        //不为none代表有网络
        if ('none' != networkType) {
          that.globalData.nonetwork = true
          //网络状态变化事件的回调函数   开启网络监听，监听小程序的网络变化
          wx.onNetworkStatusChange(function (res) {
            if (res.isConnected) {
              //网络变为有网
              that.globalData.nonetwork = true
            } else {
              //网络变为无网
              that.globalData.nonetwork = false
            }
          })
        } else {
           //无网状态
          wx.onNetworkStatusChange(function (res) {
            if (res.isConnected) {
              that.globalData.nonetwork = true
            } else {
              that.globalData.nonetwork = false
              wx.navigateTo({
                url: '/pages/nonetwork/nonetwork',
              })
            }
          })
        }
      },
    })
  },
  onLoad() {
    //判断是否网络
   if (app.globalData.nonetwork) {
     this.setData({
       nonetwork: true
     })
   } else {
     this.setData({
       nonetwork: false
     })
     wx.showToast({
       title: '请连接网络',
       icon: 'none',
       duration: 2000
     })
     wx.navigateTo({
      url: '/pages/nonetwork/nonetwork',
    })
   }
 },
  globalData: {
    userInfo: null,
    //图片路径
    // imgPath:'http://static.lianhequnmei.com/images',
    imgPath:'http://qnstatic.lianhequnmei.com/images',
    //是否参与计划前( 是否会员 )
    beforePlanned:false,
    beforePlannedSatus:0,
    //tarbarActive
    tabbarActive:'service',
    //接口地址基础部分
    baseUrl:'https://www.lianhequnmei.com',
    //登录数据
    loginData:null,
    //七牛上传网址
    qiNiuUrl:'http://qnstatic.lianhequnmei.com',
    //七牛bucket
    qiNuiBucket:'mojielong-apps',
    
    //code
    code:'',
    //channel
    channel:'',
    is_share:'',
    //hash
    hash:'lhbb',

    //im
    im_SDKAPPID:'1400761091',

    //statusBarHeight
    statusBarHeight:0,

    userEnterAppletMode:0,

    iskefu:false,

    nonetwork: false   //判断是否有网络



  },


})
